package cn.school.student.common.converter;

import cn.school.student.common.enumdir.GenderEnum;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

public class GenderConverter implements Converter<String> {

    //java中的类型
    @Override
    public Class supportJavaTypeKey() {
        return String.class;
    }
    //excel中的类型
    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    //excel转java类型
    @Override
    public String convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        String cellDataValue=cellData.getStringValue();
        String value= GenderEnum.getByLabel(cellDataValue).getValue();
        if(value==null){
            throw new Exception("性别输入不正确");
        }
        return value;
    }
    //java属性转excel
    @Override
    public CellData convertToExcelData(String integer, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return null;
    }
}
